function e(e, a, o) {
    return a in e ? Object.defineProperty(e, a, {
        value: o,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[a] = o, e;
}

var a = require("../../../utils/function.js"), o = require("../../../config.js"), t = require("../../../api.js"), s = getApp();

Page({
    data: {
        total_price:'',
        estimated_form_time:'',
        img: a.userImg,
        order: null,
        driver: wx.getStorageSync("serverDriver"),
        reduce: null,
        total: null,
        checkOrder: !0,
        checkCoupon: !0,
        wechatOrZhifubao: !0,
        order_no: "",
        couponList: [],
        choose_coupon: {
            is_open: !1,
            message: {}
        },
        actions: [],
        cancelText: "取消",
        show: !1,
        cancelWithMask: !0,
        clickpay: !0,
        wxpays: "",
        order_nos: "",
        pay_prices: "",
        coponids: ""
    },
    checkOrderHandler: function() {
        this.setData({
            checkOrder: !this.data.checkOrder
        });
    },
    checkCouponHandler: function() {
        this.setData({
            checkCoupon: !this.data.checkCoupon
        });
    },
    callPhoneHandler: function(e) {
        console.log(e.currentTarget.dataset.phone), wx.makePhoneCall({
            phoneNumber: e.currentTarget.dataset.phone
        });
    },
    bindCasPickerChange: function() {},
    choosePayWayHandler: function() {
        this.setData({
            wechatOrZhifubao: !this.data.wechatOrZhifubao
        });
    },
    openActionsheet: function() {
        this.setData({
            show: !0
        });
    },
    closeActionSheet: function() {
        this.setData({
            show: !1
        });
    },
    clickAction: function(a) {
        var o, t = this, s = a.detail.index;
        switch (this.setData((o = {}, e(o, "actions[" + s + "].loading", !0), e(o, "actionType", s), 
        e(o, "clickpay", !0), o)), s) {
          case 0:
            this.wechatPay();
            break;

          case 1:
            this.balancePay();
        }
        setTimeout(function() {
            var a;
            t.setData((a = {}, e(a, "show", !1), e(a, "actions[" + s + "].loading", !1), a));
        }, 100);
    },
    wechatPay: function() {
        var e = this;
        s.request({
            url: t.order.prepay,
            method: "post",
            data: {
                coponid: e.data.coponids,
                order_no: e.data.order_nos,
                pay: e.data.wxpays,
                pay_price: e.data.total_price,
                // pay_price: e.data.pay_prices,
                pay_type: 1
            },
            success: function(a) {
                1 == a.code && wx.requestPayment({
                    timeStamp: a.data.timeStamp,
                    nonceStr: a.data.nonceStr,
                    package: a.data.package,
                    signType: a.data.signType,
                    paySign: a.data.paySign,
                    success: function(a) {
                        console.log("支付回调结果", a), s.gateway(e.data.order_nos, "10"), wx.showToast({
                            title: "支付成功",
                            icon: "success"
                        }), wx.redirectTo({
                            url: "/pages/userOrder/allOrder/allOrder"
                        });
                    },
                    fail: function(e) {
                        wx.showToast({
                            title: "支付失败",
                            icon: "none",
                            mask: !0
                        });
                    },
                    complete: function(e) {}
                });
            }
        });
    },
    balancePay: function() {
        var e = this;
        s.request({
            url: t.order.prepay,
            method: "post",
            data: {
                coponid: e.data.coponids,
                order_no: e.data.order_nos,
                pay: e.data.wxpays,
                  pay_price: 13,
                // pay_price: e.data.pay_prices,
                pay_type: 2
            },
            success: function(a) {
                1 == a.code ? (s.gateway(e.data.order_nos, "10"), wx.showToast({
                    title: "余额支付成功",
                    icon: "success",
                    duration: 1e3
                }, wx.redirectTo({
                    url: "/pages/userOrder/allOrder/allOrder"
                }))) : -1 == a.code ? wx.showModal({
                    content: "余额不足，是否进行充值",
                    success: function(e) {
                        e.confirm && wx.redirectTo({
                            url: "/pages/driver/top-up/top-up"
                        });
                    }
                }) : wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1e3
                });
            }
        });
    },
    payHandler: function(e) {
        var a = this, o = e.currentTarget.dataset.wxpay, t = e.currentTarget.dataset.order_no, s = this.data.pay_price, n = this.data.choose_coupon.message.id;
        a.setData({
            wxpays: o,
            order_nos: t,
            pay_prices: s,
            coponids: n
        }), a.openActionsheet();
    },
    open_coupon: function() {
        var e = this.data.choose_coupon;
        e.is_open = !0, this.setData({
            choose_coupon: e
        });
    },
    getCoupon: function(e) {
        var a = e.detail.value;
        if (0 != a) {
            var o = this.data, t = o.choose_coupon, s = o.couponList, n = (o.pay_price, o.order);
            t.message = s[a];
            var r = parseFloat(n.actual_price) - parseFloat(t.message.price);
            console.log(r), this.setData({
                choose_coupon: t,
                pay_price: r.toFixed(2)
            });
        }
    },
    closeCouponHandler: function() {
        var e = this.data, a = e.choose_coupon, o = (e.couponList, e.pay_price, e.order);
        a.is_open = !1, a.message = {}, this.setData({
            choose_coupon: a,
            pay_price: o.actual_price
        });
    },
    getCouponHandler: function() {
        var e = this.data.choose_coupon;
        e.is_open = !1, this.setData({
            choose_coupon: e
        });
    },
    onLoad: function(e) {
        this.setPayWay(), this.setData({
            order_no: e.order_no
        }), e.uid && s.shareCouponsMessage(e.uid);
    },
    setPayWay: function() {
        var e = this, a = o.actions;
        s.request({
            url: t.user.payWay,
            method: "post",
            success: function(o) {
                console.log(a[1]), 0 == o.data.open_weixin && (a = [ a[1] ]), e.setData({
                    actions: a
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {
        var e = this;
        s.request({
            url: t.order.order_cost,
            method: "post",
            data: {
                order_no: e.data.order_no
            },
            success: function(a) {
                if (1 == a.code) {
                    1 == a.data.is_pay && wx.redirectTo({
                        url: "../paidDetail/paidDetail?order_no=" + e.data.order_no
                    }), e.setData({
                        order: a.data,
                        pay_price: a.data.actual_price,
                        work_phone: a.data.work_phone,
                        signature: a.data.signature,
                        total_price:a.data.total_price,
                        estimated_form_time:a.data.estimated_form_time
                    });
                    var o = [];
                    if (0 == a.data.CouponList.length) o = []; else {
                        o = [ {
                            name: "优惠券名称",
                            price: "价格"
                        } ];
                        for (var t = 0; t < a.data.CouponList.length; t++) o.push(a.data.CouponList[t]);
                    }
                    e.setData({
                        couponList: o
                    });
                }
            }
        }), this.setData({
            choose_coupon: {
                is_open: !1,
                message: {}
            }
        });
    },
    priceRule: function(e) {
        console.log(e, "2222222222"), wx.navigateTo({
            url: e.currentTarget.dataset.url
        });
    },
    onShareAppMessage: function() {
        return {
            title: s.shareAppMessage().title,
            imageUrl: s.shareAppMessage().imageUrl,
            desc: s.shareAppMessage().desc,
            path: s.shareAppMessage().path
        };
    }
});